package com.boot.sms;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@AutoConfiguration
//自动装配的智能判断,仅在类路径中存在指定类时才生效配置
@ConditionalOnClass({SmsService.class})
//激活外部化配置绑定
@EnableConfigurationProperties(SmsProperties.class)
//指定条件自动装配
@ConditionalOnProperty(prefix = "sms", value = "enable", matchIfMissing = true)
public class SmsAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SmsService smsService(SmsProperties smsProperties) {
        return new SmsService(smsProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public SmsTemplate smsTemplate(SmsService smsService) {
        return new SmsTemplate(smsService);
    }
}
